<template>
<!-- 计时器组件 -->
	<span :endText="endText">
		<p>总时长: 120分钟</p>
        <p>剩余时间: <strong>{{content}}</strong></p>
	</span>
</template>
<script>
export default {
	data() {
		return {
			content: ''
		};
	},
	props: {
		endText: {
			type: String,
			default: '已结束'
		}
	},
	methods: {
		countdowm(timestamp) {
			let self = this;
			let timer = setInterval(function() {
				let nowTime = new Date().getTime();
				let t = timestamp - nowTime;
				if (t > 0) {
					let hour = Math.floor((t / 3600000) % 24);
					let min = Math.floor((t / 60000) % 60);
					let sec = Math.floor((t / 1000) % 60);
					hour = hour < 10 ? '0' + hour : hour;
					min = min < 10 ? '0' + min : min;
					sec = sec < 10 ? '0' + sec : sec;
					let format = '';
					if (hour > 0) {
						format = `${hour}:${min}:${sec}`;
					}
					if (hour <= 0) {
						format = `${min}:${sec}`;
					}
					self.content = format;
				} else {
					clearInterval(timer);
					self.content = self.endText;
				}
			}, 1000);
		}
	}
};
</script>
